<template>
	<div class="container">
		<div class="jx-container">
      <div class="select-type" v-loading="boo.fileing">
        <div class="item">
          <span>机构状态</span>
          <div class="right">
            <span v-for="(item, index) in shopStatus" :key="index" :class="params_list.status == item.label ? 'active' : ''" @click="selected(1,item)">{{item.label}}({{item.value}})</span>
          </div>
        </div>
        <div class="item">
          <span>机构类型</span>
          <div class="right"> 
            <span v-for="(item, index) in typeList" :key="index" :class="params_list.type == item.label ? 'active' : ''" @click="selected(2,item)">{{item.label}}({{item.value}})</span>
          </div>
        </div>
        <div class="item table-item">
          <div class="right">
            <div class="item-inline">
              <span>所在地区</span>
              <el-cascader
                class="tel-value"
                v-model="params_list.address"
                :options="options"
                :props="props"
                @change="handleChange">
              </el-cascader>
            </div>
            <div class="item-inline">
              <span>机构名称</span>
              <el-input class="tel-value" v-model="params_list.name" placeholder="请输入机构名称"></el-input>
            </div>
            <div class="item-inline">
              <span>是否认证</span>
              <el-select class="tel-value" v-model="params_list.isservice" placeholder="请选择">
                <el-option label="是" value="true"></el-option>
                <el-option label="否" value="false"></el-option>
              </el-select>
            </div>
            <div class="item-inline">
              <el-button class="jx-btn" type="primary" @click="search">搜索</el-button>
            </div>
          </div>
        </div>
      </div>
      <div class="jx-table">
        <div class="title">
          <img class="icon" src="/static/img/icon-platform.png"/>
          机构列表
        </div>
        <el-table :data="list" border style="width: 100%" v-loading="boo.loading">
          <el-table-column type="index" label="序列" width="60" align="center">
            <template slot-scope="scope">
              <span>{{(scope.$index + 1) + ((params_list.page - 1) * params_list.size)}}</span>
            </template>
          </el-table-column>
          <el-table-column prop="institutionName" label="机构名称" width="150" align="center" :show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column prop="institutionProvinceCity" label="所在地区" align="center" :show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column prop="registerAt" label="注册时间" width="150" align="center" :show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column prop="institutionCatalog" label="类型" align="center">
          </el-table-column>
          <el-table-column prop="institutionBalanceCatalog" label="结算方式" align="center">
          </el-table-column>
          <el-table-column prop="isRealname" label="是否认证" align="center">
            <template slot-scope="scope">
              {{scope.row.isRealname ? '是' : '否'}}
            </template>
          </el-table-column>
          <el-table-column label="操作" width="150" align="center">
            <template slot-scope="scope">
              <el-button @click="viewRow(scope.row)" type="text" size="small">查看详情</el-button>
              <!-- <el-button @click="hiddenRow(scope.row)" type="text" size="small">{{scope.row.institutionStatus == '正常' ? '冻结' : '解冻'}}</el-button> -->
            </template>
          </el-table-column>
        </el-table>
        <div v-if="list.length != 0" class="jx-pagination">
          <el-pagination @current-change="pageChange" @size-change="handleSizeChange" :current-page="params_list.page" :page-sizes="[10,50,100]" :page-size="params_list.size" layout="total, sizes, prev, pager, next, jumper"
            :total="other.allRow">
          </el-pagination>
        </div>
      </div>
    </div>
	</div>
</template>

<script>
	export default {
		data() {
			return {
        https: {
          list: this.$api.merchant.sflist,
          common: this.$api.common,
        },
        boo: {
          loading: false,
        },
        other: {
          allRow: 1,
        },
        list: '',
        params_list: {
          page: 1,
          size: 10,
          status: '全部',
          type: '全部',
          address: '',
          name: '',
          isservice: '',
        },
        props: {
          expandTrigger: 'click', 
          value: 'field',
          label: 'field',
        },
        options: '',
        shopStatus: '',
        typeList: '',
			}
		},
		mounted(){
      let _self = this
      _self.getList()
      _self.getAddress()
      _self.getDict('institutionStatus')
      _self.getDict('institutionCatalog')
    },
		methods: {
      getDict(type){
        let _self = this
        let params = {
          dictCode: type,
        }
        // 新建判断Map
        let actions = (i,list,)=>{
          return new Map([
            ['institutionCatalog',()=>{
              let dataValueBatch2 = []
              list.forEach(item => {
                dataValueBatch2.push({
                  value: '',
                  label: item,
                })
              });
              _self.typeList = dataValueBatch2
              _self.typeList.unshift({
                value: '',
                label: '全部',
              })
            }],
            ['institutionStatus',()=>{
              let dataValueBatch = []
              list.forEach(item => {
                dataValueBatch.push({
                  value: '',
                  label: item,
                })
              });
              _self.shopStatus = dataValueBatch
              _self.shopStatus.unshift({
                value: '',
                label: '全部',
              })
            }]
          ]).get(i).call(this)
        }
        let success = (res)=>{
          if(res.data.retCode == 1){
            actions(type,res.data.retObject)
          }else{
            _self.$message.error(res.data.retMsg)
          }
        }
        _self.$axios.get(_self.https.common.dict, params, success) 
      },
      getAddress(){
        let _self = this
        let success = (res)=>{
          res = res.data
          if(res.retCode == 1){
            _self.options = res.retObject
          }else{
            _self.$message.error(res.retMsg)
          }
        }
        _self.$axios.get(_self.https.common.address, {}, success) 
      },
      setValue(type, name, val){
        let _self = this
        if(type == '机构状态'){
          let idx = _self.shopStatus.findIndex(item=>item.label == name)
          if(idx == -1) return 
          _self.shopStatus[idx].value = val
        }
        if(type == '机构类型'){
          let idx = _self.typeList.findIndex(item=>item.label == name)
          if(idx == -1) return
          // if(idx == -1) return _self.$message.error('无此店铺类型，请检查接口返回值')
          _self.typeList[idx].value = val
        }
      },
      getList(){
        let _self = this
        let params = {
          institutionStatus: _self.params_list.status == '全部' ? '' : _self.params_list.status,
          institutionCatalog: _self.params_list.type == '全部' ? '' : _self.params_list.type,
          institutionProvinceCity: _self.params_list.address,
          institutionName: _self.params_list.name,
          isRealname: _self.params_list.isservice,
          orderBy: '',
          pageNumber: _self.params_list.page,
          pageSize: _self.params_list.size,
        }
        _self.boo.loading = true
        let success = (res)=>{
          res = res.data
          if(res.retCode == 1){
            _self.list = res.retObject.list
            _self.other.allRow = Number(res.retObject.totalRow)
            for(let key in res.retObject.paras.institutionStatus){
              _self.setValue('机构状态', key, res.retObject.paras.institutionStatus[key])
            }
            for(let key in res.retObject.paras.institutionCatalog){
              _self.setValue('机构类型', key, res.retObject.paras.institutionCatalog[key])
            }
          }else{
            _self.$message.error(res.retMsg)
          }
          _self.boo.loading = false
        }
        _self.$axios.get(_self.https.list.list, params, success) 
      },
      pageChange(val){
        let _self = this
        _self.params_list.page = val
        _self.getList()
      },
      handleSizeChange(val) {
        let _self = this
        _self.params_list.size = val
        _self.getList()
      },
      selected(num, item){
        let _self = this
        switch (num) {
          case 1:
            _self.params_list.status = item.label
            break;
          case 2:
            _self.params_list.type = item.label
            break;
        }
        _self.getList()
      },
      search(){
        let _self = this
        _self.getList()
      },
      viewRow(item){
        let _self = this
        let params = {
          path: '/merchant/detail/sflist_detail?id=',
          query: item.institutionId
        }
        _self.$router.push(params.path + params.query)
      },
      hiddenRow(item){
        let _self = this
      },
    }
	}

</script>
<style scoped lang="sass">
  .select-type .table-item .right span
    width: 62px
</style>
